package com.example.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.common.utils.DateFormatUtil;
import com.example.dao.SuppliesRealinfoMapper;
import com.example.model.entity.SuppliesRealinfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;

@Component
@Slf4j
public class realinfoTask {

    @Autowired
    private SuppliesRealinfoMapper suppliesRealinfoMapper;

    @Scheduled(cron = "0 0 12 * * ?")//每天凌晨执行一次，删除90天前的上报信息
    public void realinfoTask() throws Exception {
        //获取90天前日期
        String beforeDate = DateFormatUtil.getBeforeMonthString(new Date(),3);
        QueryWrapper<SuppliesRealinfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().le(SuppliesRealinfo::getCreateTime,beforeDate);
        int num = suppliesRealinfoMapper.delete(queryWrapper);
    }
}
